Inspired by the Elipse.c program, I discovered how to fill a buffer. Perhaps this was a duhhh-moment on my part, but I learned that every time I invoke DoLinear() it's actually putting a start and end point into the buffer. Anyway, follow me in this logic and see if this makes sense.
void profile_3D_axis_rot_points(float rot_theta, int rotation_axis)
{
int x=0,y=1,z=2;
int h=0,v=1,i;
rot_theta = rot_theta * (PI/180); //convert to radians
switch (rotation_axis)
{
case ROT_about_X:
for (i = 0; i < 601; i++)
{
profile_3D_mat[i][x] = profile_2D_mat[i][h];
profile_3D_mat[i][y] = profile_2D_mat[i][v] * sinf(rot_theta);
profile_3D_mat[i][z] = profile_2D_mat[i][v] * cosf(rot_theta);
}
break;
case ROT_about_Y:
for (i = 0; i < 601; i++)
{
profile_3D_mat[i][x] = profile_2D_mat[i][v] * sinf(rot_theta);
profile_3D_mat[i][y] = profile_2D_mat[i][h];
profile_3D_mat[i][z] = profile_2D_mat[i][v] * cosf(rot_theta);
}
break;
}
}
//----------now to fill a buffer---------------------
void fill_buffer(int rot_axis, int start_theta_index, int dir)
{
int x=0,y=1,z=2;
int h=0,v=1,i;
float theta_rad = 0.0;
OpenBuf();
get_initial_position(); //function that grabs current pos of all axes
start_theta_index = start_theta_index + 300; //adjust to match array index
//example if fill_buffer(ROT_about_X,-155,1) then start_theta_index=-155 + 300 means i=145
switch (rot_axis)
{
case ROT_about_X:
if (dir > 0) //move fwd about x-axis
{
for (i = start_theta_index; i < 601; i++)
{
x1 = profile_3D_mat[i][x]; //Dx
y1 = profile_3D_mat[i][y]; //Dy
v1 = profile_3D_mat[i][z]; //Dz
*rotation_theta_X = (i-300); //keep track of current rotation angle for axis at pointer
u1 = *rotation_theta_X/10 * Deg2RotX; //Rx drives detector angle to point to rotation origin
z1 = z0; //Sx
a1 = a0; //Sy
b1 = b0; //Sz
c1 = c0; //Ry
DoLinear(); //add linear segment to buffer
//set start pos to last pos for all axes
x0 = x1;
y0 = y1;
v0 = v1;
u0 = u1;
z0 = z1;
a0 = a1;
b0 = b1;
c0 = c1;
}
}
else if (dir < 0) //move rev about x-axis
{
for (i = start_theta_index; i > 0; i--)
{
x1 = profile_3D_mat[i][x]; //Dx
y1 = profile_3D_mat[i][y]; //Dy
v1 = profile_3D_mat[i][z]; //Dz
*rotation_theta_X = (i-300); //keep track of current rotation angle for axis
u1 = *rotation_theta_X/10 * Deg2RotX; //Rx drives detector angle to point to rotation origin
z1 = z0; //Sx
a1 = a0; //Sy
b1 = b0; //Sz
c1 = c0; //Ry
DoLinear(); //add linear segment to buffer
//set start pos to last pos for all axes
x0 = x1;
y0 = y1;
v0 = v1;
u0 = u1;
z0 = z1;
a0 = a1;
b0 = b1;
c0 = c1;
}
}
break;
case ROT_about_Y:
if (dir > 0) //move fwd about y-axis
{
for (i = start_theta_index; i < 601; i++)
{
x1 = profile_3D_mat[i][x]; //Dx
y1 = profile_3D_mat[i][y]; //Dy
v1 = profile_3D_mat[i][z]; //Dz
*rotation_theta_Y = (i-300); //keep track of current rotation angle for axis
u1 = u0
z1 = z0; //Sx
a1 = a0; //Sy
b1 = b0; //Sz
c1 = *rotation_theta_Y/10 * Deg2RotY; //Ry to point to rotation center
DoLinear(); //add linear segment to buffer
//set start pos to last pos for all axes
x0 = x1;
y0 = y1;
v0 = v1;
u0 = u1;
z0 = z1;
a0 = a1;
b0 = b1;
c0 = c1;
}
}
else if (dir < 0) //move rev about y-axis
{
for (i = start_theta_index; i > 0; i--)
{
x1 = profile_3D_mat[i][x]; //Dx
y1 = profile_3D_mat[i][y]; //Dy
v1 = profile_3D_mat[i][z]; //Dz
*rotation_theta_Y = (i-300); //keep track of current rotation angle for axis
u1 = u0; //Ry
z1 = z0; //Sx
a1 = a0; //Sy
b1 = b0; //Sz
c1 = *rotation_theta_Y/10 * Deg2RotY; //Ry to point to center
DoLinear(); //add linear segment to buffer
//set start pos to last pos for all axes
x0 = x1;
y0 = y1;
v0 = v1;
u0 = u1;
z0 = z1;
a0 = a1;
b0 = b1;
c0 = c1;
}
}
break;
}
}
//---------function that runs motion
int amc_linear_move(void) //
{
DefineCoordSystem8(axis_0DX,axis_1DY,axis_2SX,axis_3SY,axis_4SZ,axis_5RY,axis_6RX,axis_7DZ);
VM = 600;
A = 800;
CS0_Flushed=TRUE;
ExecBuf();
while(!CheckDoneBuf() )
{
if(jogEnableFlag == 1 && *jogVelocity == 0) //condition to test if operator depressed rotation jog button
{
StopCoordinatedMotion();
while(CS0_StoppingState < 3)
{
//wait until stop
}
ClearStopImmediately();
jogEnableFlag = 0;
break;
}
}
}
//-----commanding routine
int about_x=0,about_y=1,fwd=1,rev=-1;
profile_2D_pionts(); //run once upon startup
//function if x-axis rotation selected with plane tilted by 15.5 degrees
profile_3D_axis_rot_points(155, about_x); //15.5 deg about x-axis
//move forward on profile
fill_buffer(about_x, 155, fwd);
amc_linear_move(); //execute buffer
For simplicity and program execution efficiency, I can combine profile_3D_axis_rot_points() and fill_buffer() functions. In fact in my code I have that. I just broke it up in this write up to make it clear.
Anyway, this approach will not work for me. Although the motion seems to be giving me what I need, it seems that any direction of motion I select, either going forward or reverse in either about-x or about-y axis, it only goes in ONE direction. Mainly the direction that is first initiated. My guess is that when I stop the motion by invoking the StopCoordinatedMotion() function after releasing the button, it doesn't clear the buffer. Any subsequent selection I make, causes the motion to continue moving from where it left off. I was under the impression that ClearStopImmediately() cleared any remaining elements in the buffer.
Any thoughts?